<!DOCTYPE html
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>AsciiMath Formula Input</title>
  <script type="text/javascript" src="../../../popups/popup.js"></script>
  <script type="text/javascript" src="../ASCIIMathML.js"></script>
  <link rel="stylesheet" type="text/css" href="../../../popups/popup.css" />

  <style type="text/css">
	/* <![CDATA[ */
	#outputNode,#inputText,#mathml {
		padding:5px;
		background-color:white;
		width:98%;
		height:200px;
		font-size:1.3em;
		border: 1px solid darkgrey;
		overflow:auto;
	}
	#clickInput {
		width:100%;
		border-collapse:collapse;
		background-color: white;
		text-align:center;
	}
	#clickInput td {
		border: thin solid gray;
		cursor:pointer;
		font-size:1.1em;
		
	}
	h3 {
		font-size:1.6em;
	}
	/* ]]> */
  </style>
  <script type="text/javascript">
 // <![CDATA[
   window.resizeTo(500, 300);
var showasciiformulaonhover = false;
if (typeof Xinha == "undefined")
	Xinha = window.opener.Xinha;

function i18n(str) {
  return (Xinha._lc(str, 'Equation'));
}
function set (string)
{
	var inputField = document.getElementById("inputText");
	inputField.value += string;
	preview();
	inputField.focus();
	return false;
}
function preview() {
  if (document.getElementById("inputText") != '') {
      var str = document.getElementById("inputText").value;
      var outnode = document.getElementById("outputNode");
      var newnode = AMcreateElementXHTML("div");
      newnode.setAttribute("id","outputNode");
      outnode.parentNode.replaceChild(newnode,outnode);
      outnode = document.getElementById("outputNode");
      var n = outnode.childNodes.length;
      for (var i = 0; i < n; i++)
        outnode.removeChild(outnode.firstChild);
      outnode.appendChild(document.createComment("`"+str+"`"));
      AMprocessNode(outnode,true);
  }
}
function Init() {
	__dlg_translate('Equation');
	__dlg_init();
	var param = window.dialogArguments;
	var cfg = param["editor"].config;
	
	mathcolor = cfg.Equation.mathcolor;
	mathfontfamily = cfg.Equation.mathfontfamily;
	
	var inputField = document.getElementById("inputText"); 
	
	if (param["editedNode"] && param["editedNode"].tagName.toLowerCase() == 'span')
	{
		var formula = param["editedNode"].getAttribute("title").replace(/^`*(.*?)`*$/m,"$1");
		if (!formula) formula = param["editedNode"].innerHTML.replace(/^`*(.*?)`*$/m,"$1"); 
		inputField.value = formula;
		preview();
	}
	else inputField.value = '';
	inputField.focus();
}
  
function onOK() {
 	
 var param = {
 	"editedNode":window.dialogArguments.editedNode,
 	"formula" : document.getElementById("inputText").value
 };
 
 __dlg_close(param);
  return false;
}

function onCancel() {
  __dlg_close(null);
  return false;
}

function translate() {
  if (!AMtranslated) { // run this only once
    AMtranslated = true;
    AMinitSymbols();
    AMprocessNode(document.getElementById("clickInput"),true);
    preview();
  }
}
window.onload = Init;

function AMnode2string(inNode,indent) {
// thanks to James Frazer for contributing an initial version of this function
   var i, str = "";
   if(inNode.nodeType == 1) {
       var name = inNode.nodeName.toLowerCase(); // (IE fix)
       str = "\r" + indent + "<" + name;
       for(i=0; i < inNode.attributes.length; i++)
           if (inNode.attributes[i].nodeValue!="italic" &&
               inNode.attributes[i].nodeValue!="" &&  //stop junk attributes
               inNode.attributes[i].nodeValue!="inherit" && // (mostly IE)
               inNode.attributes[i].nodeValue!=undefined &&
               inNode.attributes[i].nodeName[0] != '-'
               )
               str += " "+inNode.attributes[i].nodeName+"="+
                     "\""+inNode.attributes[i].nodeValue+"\"";
       if (name == "math") 
           str += " xmlns=\"http://www.w3.org/1998/Math/MathML\"";
       str += ">";
       for(i=0; i<inNode.childNodes.length; i++)
           str += AMnode2string(inNode.childNodes[i], indent+"  ");
       if (name != "mo" && name != "mi" && name != "mn") str += "\r"+indent;
       str += "</" + name + ">";
   }
   else if(inNode.nodeType == 3) {
       var st = inNode.nodeValue;
       for (i=0; i<st.length; i++)
           if (st.charCodeAt(i)<32 || st.charCodeAt(i)>126)
               str += "&#"+st.charCodeAt(i)+";";
           else if (st.charAt(i)=="<" && indent != "  ") str += "&lt;";
           else if (st.charAt(i)==">" && indent != "  ") str += "&gt;";
           else if (st.charAt(i)=="&" && indent != "  ") str += "&amp;";
           else str += st.charAt(i);
   }
   return str;
} 
function showMathML()
{
	var math = document.getElementById("outputNode").getElementsByTagName("math")[0];
	if (math)
		math.parentNode.innerHTML = '<pre>'+Xinha.htmlEncode(AMnode2string(math,''))+'</pre>';
}
// ]]>
</script>

</head>

<body class="dialog">
<div class="title">AsciiMath Formula Input</div>
<!--
Table modified from CharacterMap for ASCIIMathML by Peter Jipsen
HTMLSource based on HTMLArea XTD 1.5 (http://mosforge.net/projects/htmlarea3xtd/) modified by Holger Hees
Original Author - Bernhard Pfeifer novocaine@gmx.net
-->
<table  id="clickInput">
<tr>
<td colspan="3" class="character" title="(x+1)/(x-1)" onclick="set('(x+1)/(x-1)')">`(x+1)/(x-1)`</td>
<td colspan="2" class="character" title="x^(m+n)" onclick="set('x^(m+n)')">`x^(m+n)`</td>
<td colspan="2" class="character" title="x_(mn)" onclick="set('x_(mn)')">`x_(mn)`</td>
<td colspan="2" class="character" title="sqrt(x)" onclick="set('sqrt(x)')">`sqrt(x)`</td>
<td colspan="3" class="character" title="root(n)(x)" onclick="set('root(n)(x)')">`root(n)(x)`</td>
<td colspan="2" class="character" title="&quot;text&quot;" onclick="set('&quot;text&quot;')">`&quot;text&quot;`</td>
<td colspan="2" class="character" style="cursor:default"></td>
</tr><tr>
<td colspan="2" class="character" title="dy/dx" onclick="set('dy/dx')">`dy/dx`</td>
<td colspan="3" class="character" title="lim_(x-&gt;oo)" onclick="set('lim_(x-&gt;oo)')">`lim_(x-&gt;oo)`</td>
<td colspan="3" class="character" title="sum_(n=1)^oo" onclick="set('sum_(n=1)^oo')">`sum_(n=1)^oo`</td>
<td colspan="3" class="character" title="int_a^bf(x)dx" onclick="set('int_a^bf(x)dx')">`int_a^bf(x)dx`</td>
<td colspan="3" class="character" title="[[a,b],[c,d]]" onclick="set('[[a,b],[c,d]]')">`[[a,b],[c,d]]`</td>
<td colspan="2" class="character" title="((n),(k))" onclick="set('((n),(k))')">`((n),(k))`</td>
</tr><tr>
<td class="character" title="*" onclick="set('*')">`*`</td>
<td class="character" title="**" onclick="set('**')">`**`</td>
<td class="character" title="//" onclick="set('//')">`//`</td>
<td class="character" title="\\" onclick="set('\\\\')">`\\`</td>
<td class="character" title="xx" onclick="set('xx')">`xx`</td>
<td class="character" title="-:" onclick="set('-:')">`-:`</td>
<td class="character" title="@" onclick="set('@')">`@`</td>
<td class="character" title="o+" onclick="set('o+')">`o+`</td>
<td class="character" title="ox" onclick="set('ox')">`ox`</td>
<td class="character" title="o." onclick="set('o.')">`o.`</td>
<td class="character" title="sum" onclick="set('sum')">`sum`</td>
<td class="character" title="prod" onclick="set('prod')">`prod`</td>
<td class="character" title="^^" onclick="set('^^')">`^^`</td>
<td class="character" title="^^^" onclick="set('^^^')"><span style="font-size:larger">`&and;`</span></td>
<td class="character" title="vv" onclick="set('vv')">`vv`</td>
<td class="character" title="vvv" onclick="set('vvv')"><span style="font-size:larger">`&or;`</span></td>
</tr><tr>
<td class="character" title="!=" onclick="set('!=')">`!=`</td>
<td class="character" title="&lt;=" onclick="set('&lt;=')">`&lt;=`</td>
<td class="character" title="&gt;=" onclick="set('&gt;=')">`&gt;=`</td>
<td class="character" title="-&lt;" onclick="set('-&lt;')">`-&lt;`</td>
<td class="character" title="&gt;-" onclick="set('&gt;-')">`&gt;-`</td>
<td class="character" title="in" onclick="set('in')">`in`</td>
<td class="character" title="!in" onclick="set('!in')">`!in`</td>
<td class="character" title="sub" onclick="set('sub')">`sub`</td>
<td class="character" title="sup" onclick="set('sup')">`sup`</td>
<td class="character" title="sube" onclick="set('sube')">`sube`</td>
<td class="character" title="supe" onclick="set('supe')">`supe`</td>
<td class="character" title="O/" onclick="set('O/')">`O/`</td>
<td class="character" title="nn" onclick="set('nn')">`nn`</td>
<td class="character" title="nnn" onclick="set('nnn')"><span style="font-size:larger">`&cap;`</span></td>
<td class="character" title="uu" onclick="set('uu')">`uu`</td>
<td class="character" title="uuu" onclick="set('uuu')"><span style="font-size:larger">`&cup;`</span></td>
</tr><tr>
<td class="character" title="and" onclick="set('and')">`and`</td>
<td class="character" title="or" onclick="set('or')">`or`</td>
<td class="character" title="not" onclick="set('not')">`not`</td>
<td class="character" title="=&gt;" onclick="set('==&gt;')">`=&gt;`</td>
<td class="character" title="if" onclick="set('if')">`if`</td>
<td class="character" title="&lt;=&gt;" onclick="set('&lt;=&gt;')">`&lt;=&gt;`</td>
<td class="character" title="AA" onclick="set('AA')">`AA`</td>
<td class="character" title="EE" onclick="set('EE')">`EE`</td>
<td class="character" title="_|_" onclick="set('_|_')">`_|_`</td>
<td class="character" title="TT" onclick="set('TT')">`TT`</td>
<td class="character" title="|--" onclick="set('|--')">`|--`</td>
<td class="character" title="|==" onclick="set('|==')">`|==`</td>
<td class="character" title="-=" onclick="set('-=')">`-=`</td>
<td class="character" title="~=" onclick="set('~=')">`~=`</td>
<td class="character" title="~~" onclick="set('~~')">`~~`</td>
<td class="character" title="prop" onclick="set('prop')">`prop`</td>
</tr><tr>
<td class="character" title="int" onclick="set('int')">`int`</td>
<td class="character" title="oint" onclick="set('oint')">`oint`</td>
<td class="character" title="del" onclick="set('del')">`del`</td>
<td class="character" title="grad" onclick="set('grad')">`grad`</td>
<td class="character" title="+-" onclick="set('+-')">`+-`</td>
<td class="character" title="oo" onclick="set('oo')">`oo`</td>
<td class="character" title="aleph" onclick="set('aleph')">`aleph`</td>
<td class="character" title="quad" onclick="set('quad')">`quad`</td>
<td class="character" title="diamond" onclick="set('diamond')">`diamond`</td>
<td class="character" title="square" onclick="set('square')">`square`</td>
<td class="character" title="|__" onclick="set('|__')">`|__`</td>
<td class="character" title="__|" onclick="set('__|')">`__|`</td>
<td class="character" title="|~" onclick="set('|~')">`|~`</td>
<td class="character" title="~|" onclick="set('~|')">`~|`</td>
<td class="character" title="&lt;x&gt;" onclick="set('&lt;x&gt;')">`&lt;x&gt;`</td>
<td class="character" title="/_" onclick="set('/_')">`/_`</td>
</tr><tr>
<td class="character" title="uarr" onclick="set('uarr')">`uarr`</td>
<td class="character" title="darr" onclick="set('darr')">`darr`</td>
<td class="character" title="larr" onclick="set('larr')">`larr`</td>
<td class="character" title="-&gt;" onclick="set('-&gt;')">`-&gt;`</td>
<td class="character" title="|-&gt;" onclick="set('|-&gt;')">`|-&gt;`</td>
<td class="character" title="harr" onclick="set('harr')">`harr`</td>
<td class="character" title="lArr" onclick="set('lArr')">`lArr`</td>
<td class="character" title="rArr" onclick="set('rArr')">`rArr`</td>
<td class="character" title="hArr" onclick="set('hArr')">`hArr`</td>
<td class="character" title="hata" onclick="set('hat')">`hata`</td>
<td class="character" title="ula" onclick="set('ul')">`ula`</td>
<td class="character" title="dota" onclick="set('dot')">`dota`</td>
<td class="character" title="ddota" onclick="set('ddot')">`ddota`</td>
<td class="character" title="veca" onclick="set('vec')">`veca`</td>
<td class="character" title="bara" onclick="set('bar')">`bara`</td>
<td class="character" title=":." onclick="set(':.')">`:.`</td>
</tr><tr>
<td class="character" title="NN" onclick="set('NN')">`NN`</td>
<td class="character" title="ZZ" onclick="set('ZZ')">`ZZ`</td>
<td class="character" title="QQ" onclick="set('QQ')">`QQ`</td>
<td class="character" title="RR" onclick="set('RR')">`RR`</td>
<td class="character" title="CC" onclick="set('CC')">`CC`</td>
<td class="character" title="bba" onclick="set('bb')">`bba`</td>
<td class="character" title="bbba" onclick="set('bbb')">`bbba`</td>
<td class="character" title="cca" onclick="set('cc')">`cca`</td>
<td class="character" title="fra" onclick="set('fr')">`fra`</td>
<td class="character" title="sfa" onclick="set('sf')">`sfa`</td>
<td class="character" title="tta" onclick="set('tt')">`tta`</td>
<td colspan="4" class="character" title="stackrel(-&gt;)(+)" onclick="set('stackrel(-&gt;)(+)')">`stackrel(-&gt;)(+)`</td>
<td class="character" title="upsilon" onclick="set('upsilon')">`upsilon`</td>
</tr><tr>
<td class="character" title="alpha" onclick="set('alpha')">`alpha`</td>
<td class="character" title="beta" onclick="set('beta')">`beta`</td>
<td class="character" title="gamma" onclick="set('gamma')">`gamma`</td>
<td class="character" title="Gamma" onclick="set('Gamma')">`Gamma`</td>
<td class="character" title="delta" onclick="set('delta')">`delta`</td>
<td class="character" title="Delta" onclick="set('Delta')">`Delta`</td>
<td class="character" title="epsi" onclick="set('epsi')">`epsi`</td>
<td class="character" title="zeta" onclick="set('zeta')">`zeta`</td>
<td class="character" title="eta" onclick="set('eta')">`eta`</td>
<td class="character" title="theta" onclick="set('theta')">`theta`</td>
<td class="character" title="Theta" onclick="set('Theta')">`Theta`</td>
<td class="character" title="iota" onclick="set('iota')">`iota`</td>
<td class="character" title="kappa" onclick="set('kappa')">`kappa`</td>
<td class="character" title="lambda" onclick="set('lambda')">`lambda`</td>
<td class="character" title="Lambda" onclick="set('Lambda')">`Lambda`</td>
<td class="character" title="mu" onclick="set('mu')">`mu`</td>
</tr><tr>
<td class="character" title="nu" onclick="set('nu')">`nu`</td>
<td class="character" title="pi" onclick="set('pi')">`pi`</td>
<td class="character" title="Pi" onclick="set('Pi')">`Pi`</td>
<td class="character" title="rho" onclick="set('rho')">`rho`</td>
<td class="character" title="sigma" onclick="set('sigma')">`sigma`</td>
<td class="character" title="Sigma" onclick="set('Sigma')">`Sigma`</td>
<td class="character" title="tau" onclick="set('tau')">`tau`</td>
<td class="character" title="xi" onclick="set('xi')">`xi`</td>
<td class="character" title="Xi" onclick="set('Xi')">`Xi`</td>
<td class="character" title="phi" onclick="set('phi')">`phi`</td>
<td class="character" title="Phi" onclick="set('Phi')">`Phi`</td>
<td class="character" title="chi" onclick="set('chi')">`chi`</td>
<td class="character" title="psi" onclick="set('psi')">`psi`</td>
<td class="character" title="Psi" onclick="set('Psi')">`Psi`</td>
<td class="character" title="omega" onclick="set('omega')">`omega`</td>
<td class="character" title="Omega" onclick="set('Omega')">`Omega`</td>
</tr>
</table>
<form action="javascript:void(0);">
<table style="width: 100%;border:none">
  <tr>
    <td style="width:50%">Input</td><td style="width:50%"><input type="button" onclick="showMathML()" style="float:right;font-size:10px" value="Show MathML" /><span>Preview</span></td>
  </tr>
  <tr>
    <td>
    <textarea id="inputText" onkeyup="preview()"></textarea>
    </td>
    <td>
    <div id="outputNode"></div>
    <textarea id="mathml" style="display:none"></textarea>
    </td>
  </tr>
  <tr><td colspan="2">
  <span>Based on ASCIIMathML by </span><a href="http://www.chapman.edu/~jipsen" onclick="window.open(this.href,'_blank','');return false;">Peter Jipsen</a>, 
<a href="http://www.chapman.edu" onclick="window.open(this.href,'_blank','');return false;">Chapman University</a><br />
  <span>For more information on AsciiMathML visit this page: </span><a href="http://www1.chapman.edu/~jipsen/mathml/asciimath.html" onclick="window.open(this.href,'_blank','');return false;">http://www1.chapman.edu/~jipsen/mathml/asciimath.html</a></td></tr>
</table>

<div id="buttons">
<script type="text/javascript">
// <![CDATA[
if (Xinha.is_ie)
 document.write('<span style="color:red;float:left">'+i18n('Attention Internet Explorer users: Please note that there is no WYSIWYG representation of the formula in the editor!<br />You might wish to use <a href="http://www.mozilla.com" target="_blank">Mozilla Firefox</a> instead.')+'</span>');
// ]]>
</script>
  <button type="submit" name="ok" onclick="return onOK();">OK</button>
  <button type="button" name="cancel" onclick="return onCancel();">Cancel</button>
</div>
</form>
</body>
</html>